/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tcpclient;
import java.net.*;
/* The java.io package contains the basics needed for IO operations. */
import java.io.*;
/**
 *
 * @author hpfamily
 */
public class Client {

    public  Socket client;
 
    public DataOutputStream dos;
    public DataInputStream dis;

    public static void main(String[] args)
    {
        new Client().go();

    }

    public void go()
    {
		try {
			client = new Socket("localhost",19999);
                        System.out.println("SocketClient initialized");
			dos=new DataOutputStream(client.getOutputStream());
			dis=new DataInputStream(client.getInputStream());
                        
                        
                        int y =3;
                        do
                        {
                              String inp = getMSG();
                              System.out.println(inp);
                              
                              String out = "2a, " ;
                              sendMSG(out);
                              y--;
                        }
                        while(y>0);

			//client.close();
		} catch (Exception e) {
			System.out.println("Can't connect to server");
		}
    }
    public void sendMSG(String data)
    {
		try {
			dos.writeUTF(data);
			dos.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
    public String getMSG()
    {
		String data=null;
		try {
			data=dis.readUTF();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return data;
    }

   
  
}
